﻿<shared:PageBase x:Class="Miris.HumanMilkAnalyser.WPF.PatientDataSearchPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:shared="clr-namespace:Miris.HumanMilkAnalyser.WPF.Shared"
      xmlns:userControl="clr-namespace:Miris.HumanMilkAnalyser.WPF.CustomizedUserControl"
      x:Name="CurrentPage"
      mc:Ignorable="d" 
      d:DesignHeight="580" d:DesignWidth="1160"
	  Title="PatientDataSearchPage" Style="{StaticResource DefaultPageStyle}" 
      DataContext="{Binding PatientDataSearch, Source={StaticResource Locator}}">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/Storyboard/PageStoryborad.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Page.Resources>
    <Grid HorizontalAlignment="Center">
        <Grid.ColumnDefinitions>
            <!-- Back Button -->
            <ColumnDefinition Width="Auto" />
            <!-- Main Content -->
            <ColumnDefinition Width="Auto" />
            <!-- Next Button -->
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Button Margin="0,0,30,0" Width="47" Tag="/Skins/Resource/Image/Back.png" Style="{StaticResource OpacityImageButton}" Click="ButtonReturn_Click" />
        <!-- Trasparent effect Background -->
        <Border Grid.Column="1" Style="{StaticResource PageContentContainerBorder}">
            <Border Style="{StaticResource PageContentBackgroundBorder}" />
        </Border>
        <Grid Grid.Column="1" Width="1050" Height="550">
            <Grid.RowDefinitions>
                <!-- Page Title -->
                <RowDefinition Height="55" />
                <!-- Patient Info -->
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Text="信息检索" Margin="0,15,40,0" HorizontalAlignment="Center" Style="{StaticResource PageTitleTextBlock}" />
            <Grid Grid.Row="1" Margin="20,0,20,0">
                <Grid.RowDefinitions>
                    <!-- Search Condition -->
                    <RowDefinition Height="Auto" />
                    <!-- Patient Data -->
                    <RowDefinition />
                    <!-- Selected Patient Info -->
                    <RowDefinition Height="Auto" />
                    <!-- Test Result -->
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <!-- Label -->
                        <ColumnDefinition Width="Auto" />
                        <!-- Input -->
                        <ColumnDefinition />
                        <!-- Label -->
                        <ColumnDefinition Width="Auto" />
                        <!-- Input -->
                        <ColumnDefinition />
                        <!-- Label -->
                        <ColumnDefinition Width="Auto" />
                        <!-- Input -->
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50" />
                        <RowDefinition Height="50" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="受测者ID：" VerticalAlignment="Center" Style="{StaticResource WhiteTextBlock}" />
                    <TextBox Grid.Column="1" HorizontalAlignment="Left" Text="{Binding PatientNumber}" Width="160" Height="36" Style="{StaticResource InfoTextBox}" />
                    <TextBlock Grid.Column="2" Text="母亲姓名：" VerticalAlignment="Center" Style="{StaticResource WhiteTextBlock}" />
                    <TextBox Grid.Column="3" HorizontalAlignment="Left" Text="{Binding MotherName}" Width="160" Height="36" Style="{StaticResource InfoTextBox}" />
                    <TextBlock Grid.Column="4" Text="完成测试：" VerticalAlignment="Center" HorizontalAlignment="Right" Style="{StaticResource WhiteTextBlock}" />
                    <CheckBox Grid.Column="5" IsChecked="{Binding IsFinishedTest}" Style="{StaticResource GreenCheckBoxStyle}" />
                    <TextBlock Grid.Row="1" Text="样本号码：" VerticalAlignment="Center" Style="{StaticResource WhiteTextBlock}" />
                    <TextBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" Text="{Binding SampleNumber}" IsEnabled="{Binding IsFinishedTest}" Width="160" Height="36" Style="{StaticResource InfoTextBox}" />
                    <TextBlock Grid.Column="2" Grid.Row="1" Text="测试日期：" VerticalAlignment="Center" Style="{StaticResource WhiteTextBlock}" />
                    <StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" Grid.ColumnSpan="3">
                        <userControl:DatePickerUserControl Width="158" IsEnabled="{Binding IsFinishedTest}" SelectedDate="{Binding StartDate, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBlock Text=" - " VerticalAlignment="Center" Style="{StaticResource WhiteTextBlock}" />
                        <userControl:DatePickerUserControl Width="158" IsEnabled="{Binding IsFinishedTest}" SelectedDate="{Binding EndDate, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                    <StackPanel Grid.Column="5" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
                        <Button Width="35" Tag="/Skins/Resource/Image/Search.png" 
                                Style="{StaticResource OpacityImageButton}" ToolTip="检索"
                                Command="{Binding SearchCommand}" />
                        <Button Width="40" Margin="10,0,0,0" Tag="/Skins/Resource/Image/Delete.png" ToolTip="删除受试者数据"
                                Command="{Binding DeletePatientCommand}" CommandParameter="{Binding SelectedItems, ElementName=DataGridPatients}"
                                Style="{StaticResource OpacityImageButton}" />
                    </StackPanel>
                </Grid>
                <DataGrid x:Name="DataGridPatients" Grid.Row="1" Margin="0,10,10,0" 
                              SelectedItem="{Binding SelectedPatient, Mode=OneWayToSource}" 
                              ColumnHeaderStyle="{StaticResource DefaultDataGridColumnHeader}"
                              ItemsSource="{Binding PatientList}">
                    <DataGrid.Resources>
                        <SolidColorBrush Color="LightBlue" x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Width="60" Header="修改">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="修改" Style="{StaticResource LinkButton}" 
                                                Command="{Binding UpdatePatientDataCommand}" 
                                                CommandParameter="{Binding}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Width="80" Header="顺序号" Binding="{Binding SequenceNumber}" />
                        <DataGridTextColumn Width="170" Header="病人编号" Binding="{Binding Number}" />
                        <DataGridTextColumn Width="120" Header="母亲姓名" Binding="{Binding MotherName}" />
                        <DataGridTextColumn Width="100" Header="母亲年龄" Binding="{Binding MotherAge}" />
                        <DataGridTextColumn Width="120" Header="婴儿姓名" Binding="{Binding BabyName}" />
                        <DataGridTextColumn Width="*" Header="婴儿出生日期" Binding="{Binding BabyBirthdayDisplay}" />
                    </DataGrid.Columns>
                </DataGrid>
                <StackPanel Grid.Row="2" Margin="0,20,0,0" Orientation="Horizontal">
                    <TextBlock Text="当前查看：" Style="{StaticResource WhiteTextBlock}" />
                    <TextBlock Text="{Binding SelectedPatient.MotherName}" Style="{StaticResource WhiteTextBlock}" />
                </StackPanel>
                <Button Grid.Row="2" Margin="0,10,0,0" Width="40" Tag="/Skins/Resource/Image/Delete.png" ToolTip="删除测试数据" HorizontalAlignment="Right"
                                Command="{Binding DeleteAnalysisResultCommand}" CommandParameter="{Binding SelectedItems, ElementName=DataGridAnalysisResults}"
                                Style="{StaticResource OpacityImageButton}" />
                <DataGrid x:Name="DataGridAnalysisResults" Grid.Row="3" Margin="0,10,10,0" 
                              ColumnHeaderStyle="{StaticResource DefaultDataGridColumnHeader}"
                              ItemsSource="{Binding AnalysisResultList}">
                    <DataGrid.Resources>
                        <SolidColorBrush Color="LightBlue" x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="顺序号" Width="60" Binding="{Binding SequenceNumber}" />
                        <DataGridTemplateColumn Width="80" Header="整体报告">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="查看" Style="{StaticResource LinkButton}" Command="{Binding ShowAnalysisResultReportCommand}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="80" Header="详细建议">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" 
                                              IsChecked="{Binding IncludeBreastfeedingSignificance, UpdateSourceTrigger=PropertyChanged}" 
                                              Style="{StaticResource GreenCheckBoxStyle}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="样本号" Width="140" Binding="{Binding SampleNumber}" />
                        <DataGridTextColumn Header="测试时间" Width="140" Binding="{Binding TestDateDisplay}" />
                        <DataGridTextColumn Header="母乳取样" Width="80" Binding="{Binding SampleType}" />
                        <DataGridTextColumn Header="母乳分期" Width="80" Binding="{Binding SampleStage}" />
                        <DataGridTextColumn Header="脂肪(g/100ml)" Width="120" ElementStyle="{StaticResource TestResultDataGridCell}" Binding="{Binding Fat.TestResult,StringFormat={}{0:F2}}" />
                        <DataGridTextColumn Header="总蛋白质(g/100ml)" Width="140" ElementStyle="{StaticResource TestResultDataGridCell}" Binding="{Binding CrudeProtein.TestResult,StringFormat={}{0:F2}}" />
                        <DataGridTextColumn Header="真蛋白质(g/100ml)" Width="160" ElementStyle="{StaticResource TestResultDataGridCell}" Binding="{Binding TrueProtein.TestResult,StringFormat={}{0:F2}}" />
                        <DataGridTextColumn Header="糖类(g/100ml)" Width="120" ElementStyle="{StaticResource TestResultDataGridCell}" Binding="{Binding Carbohydrate.TestResult,StringFormat={}{0:F2}}" />
                        <DataGridTextColumn Header="干物质(g/100ml)" Width="140" ElementStyle="{StaticResource TestResultDataGridCell}" Binding="{Binding TS.TestResult,StringFormat={}{0:F2}}" />
                        <DataGridTextColumn Header="总能量(kcal/100ml)" Width="140" ElementStyle="{StaticResource TestResultDataGridCell}" Binding="{Binding Energy.TestResult,StringFormat={}{0:F2}}" />
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </Grid>
        <Button Grid.Column="2" Margin="30,0,0,0" Width="47" Tag="/Skins/Resource/Image/Next.png" Style="{StaticResource OpacityImageButton}" Visibility="Hidden" />
    </Grid>
</shared:PageBase>
